package com.hruiworks.campusgroup.controller;

import com.hruiworks.campusgroup.common.BaseResponse;
import com.hruiworks.campusgroup.enums.SuccessCode;
import com.hruiworks.campusgroup.pojo.entity.User;
import com.hruiworks.campusgroup.pojo.request.FeedbackCreateRequest;
import com.hruiworks.campusgroup.service.FeedbackService;
import com.hruiworks.campusgroup.utils.AuthorityUtils;
import com.hruiworks.campusgroup.utils.ResultUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/feedback")
public class FeedBackController {

    @Resource
    private FeedbackService feedbackService;

    @PostMapping("/submit")
    private BaseResponse<Boolean> submitFeedback(@RequestBody FeedbackCreateRequest feedbackCreateRequest, HttpServletRequest httpServletRequest) {
        User user = AuthorityUtils.currentUser(httpServletRequest);
        Boolean result = feedbackService.submitFeedback(feedbackCreateRequest, user);
        return ResultUtils.success(result, SuccessCode.COMMON_SUCCESS);
    }
}
